package com.xr.miniprogram.domain.vo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xr.common.annotation.Excel;
import com.xr.miniprogram.domain.MiniProgramService;
import com.xr.miniprogram.tools.StrListTool;
import lombok.Data;

import java.math.BigDecimal;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 服务详情VO，处理图片组
 */
@Data
public class MiniProgramServiceVO {

    /** 主键 */
    private Long serviceId;

    /** 外键，来自menuid */
    private Long menuId;

    /** 服务类别id */
    private String categoryId;

    /** 服务名称 */
    private String serviceName;

    /** 服务描述 */
    private String serviceDescribe;

    /** 佣金、初始费用、起单标准 */
    private BigDecimal commission;

    /** 佣金类型（一次结清、服务完结清） */
    private Long commissionType;

    /** 特征、最多3、4个 */
    private List<String> characteristic;

    /** 封面图地址 */
    private String serviceCoverImg;

    /** 视频地址 */
    private String videoUrl;

    /** 轮播图路径，多个 */
    private List<String> swiperImgUrls;

    /** 详情图路径，多个 */
    private List<String> serviceDetailsUrls;

    /** 服务提示 */
    private String serviceTips;

    /** 是否可选择服务时长 */
    private Long serviceTime;

    /** 服务时长的起始值,1小时 */
    private Long serviceTimeStart;

    /** 服务时长的步长 */
    private Long serviceTimeStep;

    /** 选择数量 */
    private Long serviceTimeNum;

    /** 服务时长的提示list */
    private List<String> serviceTimeTips;

    /**
     * 热门服务图片
     */
    private String popularServicesImg;

    /**
     * 精品推荐图片
     */
    private HashMap<String,Object> recommendationImg;

    /**
     * 服务详情版本
     */
    private Long serviceVersion;

    /** 创建者 */
    private String createBy;

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 更新者 */
    private String updateBy;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    /**
     * 服务被下单次数
     */
    private Long serviceSum;

    public MiniProgramService toMiniProgramService(){
        MiniProgramService item = new MiniProgramService();
        item.setServiceId(serviceId);
        item.setMenuId(menuId);
        item.setCategoryId(categoryId);
        item.setServiceName(serviceName);
        item.setServiceDescribe(serviceDescribe);
        item.setCommission(commission);
        item.setCommissionType(commissionType);
        item.setCharacteristic(StrListTool.listToSingle(characteristic));
        item.setServiceCoverImg(serviceCoverImg);
        item.setVideoUrl(videoUrl);
        item.setSwiperImgUrls(StrListTool.listToSingle(swiperImgUrls));
        item.setServiceDetailsUrls(StrListTool.listToSingle(serviceDetailsUrls));
        item.setServiceTips(serviceTips);
        item.setServiceTime(serviceTime);
        item.setServiceTimeStart(serviceTimeStart);
        item.setServiceTimeStep(serviceTimeStep);
        item.setServiceTimeNum(serviceTimeNum);
        item.setServiceTimeTips(StrListTool.listToSingle(serviceTimeTips));
        item.setRecommendationImg(JSON.toJSONString(recommendationImg));
        item.setPopularServicesImg(popularServicesImg);
        item.setServiceVersion(serviceVersion);
        item.setCreateBy(createBy);
        item.setCreateTime(createTime);
        item.setUpdateBy(updateBy);
        item.setUpdateTime(updateTime);
        return item;
    }

    public static MiniProgramServiceVO toMiniProgramServiceVO(MiniProgramService item){
        MiniProgramServiceVO miniProgramServiceVO = new MiniProgramServiceVO();
        miniProgramServiceVO.setServiceId(item.getServiceId());
        miniProgramServiceVO.setMenuId(item.getMenuId());
        miniProgramServiceVO.setCategoryId(item.getCategoryId());
        miniProgramServiceVO.setServiceName(item.getServiceName());
        miniProgramServiceVO.setServiceDescribe(item.getServiceDescribe());
        miniProgramServiceVO.setCommission(item.getCommission());
        miniProgramServiceVO.setCommissionType(item.getCommissionType());
        miniProgramServiceVO.setCharacteristic(StrListTool.stringToList(item.getCharacteristic()));
        miniProgramServiceVO.setServiceCoverImg(item.getServiceCoverImg());
        miniProgramServiceVO.setVideoUrl(item.getVideoUrl());
        miniProgramServiceVO.setSwiperImgUrls(StrListTool.stringToList(item.getSwiperImgUrls()));
        miniProgramServiceVO.setServiceDetailsUrls(StrListTool.stringToList(item.getServiceDetailsUrls()));
        miniProgramServiceVO.setServiceTips(item.getServiceTips());
        miniProgramServiceVO.setServiceTime(item.getServiceTime());
        miniProgramServiceVO.setServiceTimeStart(item.getServiceTimeStart());
        miniProgramServiceVO.setServiceTimeStep(item.getServiceTimeStep());
        miniProgramServiceVO.setServiceTimeNum(item.getServiceTimeNum());
        miniProgramServiceVO.setServiceTimeTips(StrListTool.stringToList(item.getServiceTimeTips()));
        miniProgramServiceVO.setPopularServicesImg(item.getPopularServicesImg());
        miniProgramServiceVO.setRecommendationImg(JSON.parseObject(item.getRecommendationImg(), new TypeReference<HashMap<String, Object>>(){}));
        miniProgramServiceVO.setServiceVersion(item.getServiceVersion());
        miniProgramServiceVO.setCreateBy(item.getCreateBy());
        miniProgramServiceVO.setCreateTime(item.getCreateTime());
        miniProgramServiceVO.setUpdateBy(item.getUpdateBy());
        miniProgramServiceVO.setUpdateTime(item.getUpdateTime());
        return miniProgramServiceVO;
    }
}
